Skip to content

feat(sdk): DSPX-5640 negotiate DPoP htu style from server advertisement - #441

Draft
dmihalcik-virtru wants to merge 4 commits into
mainfrom
DSPX-5640-java-sdk-dpop-negotiation
Draft

dmihalcik-virtru wants to merge 4 commits into
mainfrom
DSPX-5640-java-sdk-dpop-negotiation

Conversation

@dmihalcik-virtru

@dmihalcik-virtru dmihalcik-virtru commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Proposed Changes

Fixes DSPX-5640. Part of epic DSPX-5549 (DPoP RFC 9449 migration, step 2.1). The Go equivalent is opentdf/platform#4322 (DSPX-5639); both SDKs follow the same rules.

Problem. The SDK always signs DPoP proofs with the full request URL as htu. The first DPoP servers (service v0.11.x, shipped in DSP 2.7.x) compare an RPC's htu against its procedure path, so they reject every request from a current Java client.

Fix. Pick the htu style per server origin from what the server advertises.

  • Discovery, unauthenticated, per origin:
    1. GET /.well-known/opentdf-configuration: a dpop block's rfc9449 is authoritative; otherwise a non-empty top-level dpop_signing_alg_values_supported means RFC 9449 (service v0.18.0 and later);
    2. otherwise RFC 9728 /.well-known/oauth-protected-resource with dpop_signing_alg_values_supported;
    3. otherwise legacy.
  • Caching: only definitive answers are cached, and only for 5 minutes. After that the origin is discovered again, because the KAS, gateway and IdP can be upgraded or reconfigured independently of a long-lived client. feat(sdk): make DPoP discovery cache TTL configurable #442 (stacked on this PR) makes the TTL configurable. A network error or 5xx on the well-known step uses legacy for that request only and is retried next time, so a blip can't pin a modern server to legacy. The platform origin is seeded from the builder's existing well-known fetch when it advertises, so the first request to the platform needs no extra discovery requests. The seeded entry expires on the same TTL.
  • Legacy changes only the htu, to the procedure (/pkg.Service/Method, the last two path segments, dropping any proxy prefix). The DPoP Authorization scheme, ath and nonce handling are unchanged: step-One servers accept the DPoP scheme, and strict_scheme servers require it. Non-RPC requests and token-endpoint proofs keep the full URI. Plain Bearer tokens are unaffected.
  • Override: SDKBuilder.dpopMode(DPoPMode.AUTO | LEGACY | RFC9449), default AUTO. The existing public TokenSource constructor stays fixed to RFC 9449.

Testing

  • mvn -pl sdk -am test: 459 tests, 0 failures, 9 skipped (the existing FIPS and EC skips). This was before the TTL commit. After it, DPoPModeTest, SDKBuilderTest and TokenSourceTest were re-run and all pass.
  • New DPoPModeTest (25 tests): each advertisement source, both, neither; transient failures not cached and rediscovered; definitive 404 and unparseable answers cached; LEGACY, RFC 9449 and seeded entries expiring after the TTL (using an injected clock that wraps); bootstrap seeding; both overrides; proxy-prefix, non-RPC and short-path htu; a nonce challenge in each mode.
  • SDKBuilderTest now runs in AUTO. A seeded platform signs the full URL, while a KAS with no well-known documents gets the procedure htu, both under the DPoP scheme.
  • Cross-version end-to-end coverage goes in opentdf/tests xtest: DSPX-5642.

Checklist

  • I have added or updated unit tests
  • I have added or updated integration tests (if appropriate)
  • I have added or updated documentation

The SDK always signed DPoP proofs with the full request URL as htu.
The first DPoP servers (service v0.11.x, DSP 2.7.x) compare an RPC's
htu against its procedure and reject a full URL, so a new Java client
could not talk to an old server.

Pick the htu style per server origin, mirroring the Go SDK
(sdk/auth/dpop_mode.go):
1. unauthenticated GET /.well-known/opentdf-configuration; a dpop
   block's rfc9449 is authoritative, else a non-empty top-level
   dpop_signing_alg_values_supported means RFC 9449 (service v0.18.0+),
2. else RFC 9728 /.well-known/oauth-protected-resource with that key,
3. else legacy.
Only definitive answers are cached: a non-5xx answer from the opentdf
well-known (a 4xx or an unparseable 200 means not advertised) or an
RFC 9728 advertisement. A network error or 5xx on the well-known step
uses legacy for that request only, logs a warning, and is retried on
the next request. The platform origin is seeded from the bootstrap
well-known response when it advertises, so the common case makes no
extra requests.

Legacy keeps the DPoP Authorization scheme, ath and nonce handling;
only the htu changes, to the procedure (/pkg.Service/Method, the last
two path segments, dropping any proxy prefix). Non-RPC requests and
token endpoint proofs keep the full URI, and non-DPoP Bearer tokens are
unaffected. SDKBuilder.dpopMode(AUTO | LEGACY | RFC9449; default AUTO)
overrides discovery, matching Go's WithDPoPMode.

Verified with mvn -pl sdk -am test (459 tests, 0 failures). DPoPModeTest
covers each advertisement source, both, neither, transient failures not
being cached, definitive 404 and unparseable answers being cached,
bootstrap seeding, the override, and a nonce challenge in each mode.
SDKBuilderTest now checks a seeded platform signs the full URL while a
KAS with no well-known documents gets the procedure htu.

Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
@coderabbitai

coderabbitai Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

Copy link
Copy Markdown
Contributor

…indings

Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
@github-actions

Copy link
Copy Markdown
Contributor

The KAS, gateway, and IdP can be upgraded or reconfigured independently of a
long-lived SDK client, so a discovered DPoP htu style must not be cached for
the client's lifetime. Discovered answers (RFC9449 and LEGACY) and positives
seeded from the bootstrap configuration now expire after 5 minutes, and the
origin is rediscovered on the next request. Expiry compares nanoTime by
difference so it tolerates wraparound.

Verified: DPoPModeTest (25, incl. 3 new expiry tests using an injected clock
that starts near overflow), SDKBuilderTest (12) and TokenSourceTest (22) pass
offline with JDK 21.

Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>

Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
@sonarqubecloud

Copy link
Copy Markdown

@dmihalcik-virtru dmihalcik-virtru changed the title feat(sdk): DSPX-5640 negotiate DPoP htu style from server advertisement fix(sdk): DSPX-5640 negotiate DPoP htu style from server advertisement Nov 16, 2026
@dmihalcik-virtru dmihalcik-virtru changed the title fix(sdk): DSPX-5640 negotiate DPoP htu style from server advertisement feat(sdk): DSPX-5640 negotiate DPoP htu style from server advertisement Nov 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

The Java and Go SDKs must choose the same htu form for the same server.
This brings the Java resolver in line with the Go DPoPTransport:

- Query the well-known configuration through the public Connect RPC
  (WellKnownService/GetWellKnownConfiguration) rather than a GET path.
- Only 404/405/501 or a 200 that isn't a JSON object is a final "not
  published". Any other status (401, 403, 429, 5xx), a network error,
  timeout, redirect or a body over 1 MiB is inconclusive. Redirects are no
  longer followed.
- Conclude legacy only once the well-known configuration itself answered;
  RFC 9728 metadata errors no longer block a conclusive answer.
- An inconclusive discovery is legacy for 30 s, then retried, instead of
  re-running discovery on every request.
- Concurrent requests share one discovery, run off the caller's thread with a
  10 s overall deadline; an interrupted caller fails fast with its interrupt
  flag kept while discovery finishes and is cached.
- A dpop block without a boolean rfc9449 falls back to the algs check.
- A nonce retry signs the same htu form as the challenged proof, replacing
  the header-sniffing isRpc().
- One debug record per discovery instead of a WARN per failed request.

The 5-minute TTL on conclusive answers stays; Go does not have it yet.

Verified: DPoPModeTest (41), SDKBuilderTest (12), TokenSourceTest (22),
DPoPRetryInterceptorTest (10), AuthInterceptorConnectPathTest (2) pass
offline on JDK 21. Mutation check: re-enabling redirects or removing the
shared discovery fails the redirect, concurrency and interruption tests.

Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
@github-actions

Copy link
Copy Markdown
Contributor

dmihalcik-virtru added a commit to opentdf/web-sdk that referenced this pull request Nov 17, 2026
…usive (DSPX-3397)

Reverts the conclusiveness change from 'retry DPoP discovery when the
metadata probe is inconclusive'. The Go (opentdf/platform#4322) and Java
(opentdf/java-sdk#441) SDKs conclude legacy once the well-known
configuration has answered, regardless of the RFC 9728 probe. Requiring
both probes made the web SDK rediscover every 30s, indefinitely, against
older servers whose /.well-known/oauth-protected-resource is missing CORS
headers or answered by a gateway with 401/403. It only helped a server
advertising through RFC 9728 alone during a transient failure.

The test now pins the shared rule: a definitive well-known absence keeps
legacy for the TTL despite a metadata failure, and a well-known failure
retries after 30s. README and class docs describe the same rule.

Verified: dpop-mode and dpop-providers mocha specs (34 passing); eslint
and prettier clean on the changed source and test files.

Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant